#include "TokenBlock.h"
#include <stdexcept>
#include <unordered_map>
#include<string>
int main(int argc, char *argv[]) {
  std::unordered_map<std::string, int> wordCount;

  FILE *fp = fopen(argv[1], "r");
  struct TokenBlock *tokens = get_typed_tokens(fp);

  for (struct TokenBlock *p = tokens; p; p = p->nextBlock) {
    if (p->sym != IDENT_SYM) {
      continue;
    }
    try {
      int count = wordCount.at(p->token);
      wordCount[p->token] = count + 1;
    } catch (const std::out_of_range &e) {
      wordCount[p->token] = 1;
    }
  }

  for (const auto &pair : wordCount) {
    printf("(%s: %d)\n", pair.first.c_str(), pair.second);
  }

  return 0;
}
